<?php

require __DIR__.'/../../../vendor/autoload.php';

use Gateway\app\face_v2\VerifyV2Request;
use Gateway\CommUtil;
use Gateway\ESAliyunGateway;
use Gateway\Log;

/**
 * 人脸比对,服务开通地址：https://market.aliyun.com/products/57124001/cmapi00045552.html?spm=5176.shop.result.78.553928d8UHqi88&innerSource=search#sku=yuncode3955200001
 * 管理控制台地址：https://openali.esandcloud.com/
 */

$appCode = "TODO";// TODO 替换成你自己的appcode, 获取APPCODE  可参考 https://esandinfo.yuque.com/yv6e1k/ulp2ub/fs2mm48opwox3xc4?singleDoc#
//实例化网关对象
$gateway = new ESAliyunGateway($appCode);

$request = new VerifyV2Request();
$path = 'resources'.DIRECTORY_SEPARATOR.'cn_idcard.jpeg';//拼接路径
$imageData =file_get_contents($path);
$base64String  = base64_encode($imageData);
$request->bizId = CommUtil::getTimeUUID();
$request->verifyImage = $base64String;
$request->sourceImage = $base64String;

//向网关发起请求
$rspMsg = $gateway->sendToGateWay(VerifyV2Request::$ALIYUN_URL,$request->toJsonStr());
if($rspMsg==null||strlen($rspMsg)==0){
    Log::ERROR("服务器返回内容为空");
    return;
}
Log::DEBUG("服务器返回内容为:".$rspMsg);